﻿//This file is part of Search Engine by Tomasz Kusienicki.
// 
//This Search Engine is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.
// 
//Foobar is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// 
//You should have received a copy of the GNU General Public License
//on <http://www.gnu.org/licenses/>.

using System.ComponentModel;
using System.Windows.Forms;
using AdminApp1.Common;
using AdminApp1.Models;
using AdminApp1.Presenters;

namespace AdminApp1.Views
{
    public partial class BusDetailsView : BusDetailsViewBase
    {
        protected override void OnModelSet()
        {
            base.OnModelSet();
            bnsModel.DataSource = Model;
        }

        public BusDetailsView()
        {
            InitializeComponent();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            Presenter.HandleOnClosed();
        }

        private void DataGridView1KeyDown(object sender, KeyEventArgs e)
        {
            Presenter.HandleKeyDown(sender, e);
        }

        private void DataGridView1CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if(dataGridView1.CurrentCell.ColumnIndex == 0)
            {
                e.Cancel = true;
            }
        }

        private void DataGridView1DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            Presenter.HandleUpdateException();
        }
    }

    public class BusDetailsViewBase : ViewBase<BusDetailsView, BusDetailsPresenter, BusDetailsModel> { }
}
